Have xm-test wait for the network device to detach. This is an asynchronous
authorEwan Mellor <ewan@xensource.com>
Tue, 20 Mar 2007 16:52:33 +0000 (16:52 +0000)
committerEwan Mellor <ewan@xensource.com>
Tue, 20 Mar 2007 16:52:33 +0000 (16:52 +0000)
process, so xm-test needs to poll.

Signed-off-by: Tom Wilkie <tom.wilkie@gmail.com>
tools/xm-test/tests/network-attach/network_utils.py

index 084b5ebd90690bde7cf23d27d078adcfd828406b..93fe72a811d49cafe2f1589712a7751eb73aa8f5 100644 (file)
@@ -12,6 +12,18 @@ def count_eth(console):
         FAIL(str(e))
     return len(run['output'].splitlines())
 
+def get_state(domain_name, number):
+    s, o = traceCommand("xm network-list %s | awk '/^%d/ {print $5}'" %
+                        (domain_name, number))
+    print o
+    
+    if s != 0:
+        FAIL("network-list failed")
+    if o == "":
+        return 0
+    else:
+        return int(o)
+
 def network_attach(domain_name, console):
     eths_before = count_eth(console)
     status, output = traceCommand("xm network-attach %s" % domain_name)
@@ -30,6 +42,13 @@ def network_detach(domain_name, console, num=0):
     if status != 0:
         return -1, "xm network-detach returned invalid %i != 0" % status
 
+    for i in range(10):
+        if get_state(domain_name, num) == 0:
+            break
+        time.sleep(1)
+    else:
+        FAIL("network-detach failed: device did not disappear")
+
     eths_after = count_eth(console)
     if eths_after != (eths_before-1):
        return -2, "Network device was not actually disconnected from domU"